import * as winston from "winston";
import * as DailyRotateFile from "winston-daily-rotate-file";

// Winston logger
const logger = winston.createLogger({
    level: 'info',
    format: winston.format.json(),
    defaultMeta: { service: 'my-service' },
    transports: [
        // new winston.transports.Console(),
        new DailyRotateFile({
            filename: "./environment/logs/error-%DATE%.log",
            datePattern: "YYYY-MM-DD",
            zippedArchive: true,
            maxSize: "20m",
            maxFiles: "14d",
            level: 'error',
            format: winston.format.combine(
                winston.format.timestamp({ format: 'MMM-DD-YYYY HH:mm:ss' }),
                winston.format.align(),
                winston.format.printf(info => `${info.level}: ${[info.timestamp]}: ${info.message}`),
            )
        }),
        new DailyRotateFile({
            filename: "./environment/logs/application-%DATE%.log",
            datePattern: "YYYY-MM-DD",
            zippedArchive: true,
            maxSize: "20m",
            maxFiles: "14d",
            format: winston.format.combine(
                winston.format.timestamp({ format: 'MMM-DD-YYYY HH:mm:ss' }),
                winston.format.align(),
                winston.format.printf(info => `${info.level}: ${[info.timestamp]}: ${info.message}`),
            )
        }),
        // new winston.transports.File({
        //     filename: './environment/log/server.log',
        //     format: winston.format.combine(
        //         winston.format.timestamp({ format: 'MMM-DD-YYYY HH:mm:ss' }),
        //         winston.format.align(),
        //         winston.format.printf(info => `${info.level}: ${[info.timestamp]}: ${info.message}`),
        //     )
        // }),
        // new winston.transports.File({
        //     filename: './environment/log/error.log',
        //     level: 'error',
        //     format: winston.format.combine(
        //         winston.format.timestamp({ format: 'MMM-DD-YYYY HH:mm:ss' }),
        //         winston.format.align(),
        //         winston.format.printf(info => `${info.level}: ${[info.timestamp]}: ${info.message}`),
        //     )
        // }),
    ]
});

export default logger;